package demo;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

import javax.net.ServerSocketFactory;
import javax.net.ssl.SSLServerSocketFactory;

public class HttpS {

	public static void main(String[] args) throws Exception {
		int port = 4430;
		ServerSocketFactory ssocketFactory = SSLServerSocketFactory.getDefault();

		ServerSocket ssocket = ssocketFactory.createServerSocket(port);

		// Listen for connections
		System.out.println("Listening on " + port);
		Socket socket = ssocket.accept();

		BufferedReader r = new BufferedReader(new InputStreamReader(socket.getInputStream()));
		String line;
		while ((line = r.readLine()) != null) {
			System.out.println(line);
			if (line != null && line.length() == 0 || line.length() == 1) {
				System.out.println("break");
				break;
			}
		}
		System.out.println("done");

		OutputStream out = socket.getOutputStream();

		String response = "HTTP/1.0 200 OK\r\n";
		response += "Content-Type: text/html\r\n";
		response += "Content-Length: 5\r\n\r\n";
		response += "Hello";
		out.write(response.getBytes());
		out.flush();

	}

}
